//
//  BViewController.m
//  AnimationTest
//
//  Created by Min on 2024/9/7.
//

#import "BViewController.h"

@interface BViewController ()

@end

@implementation BViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // 创建一个黑色的view作为背景
    UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 300, 300)];
    blackView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:blackView];

    // 定义射手座星座的点的位置（简化版）
    NSArray *positions = @[[NSValue valueWithCGPoint:CGPointMake(50, 60)],   // 例子中的位置，可以调整以更接近实际星座
                           [NSValue valueWithCGPoint:CGPointMake(80, 100)],
                           [NSValue valueWithCGPoint:CGPointMake(100, 150)],
                           [NSValue valueWithCGPoint:CGPointMake(150, 180)],
                           [NSValue valueWithCGPoint:CGPointMake(200, 150)],
                           [NSValue valueWithCGPoint:CGPointMake(240, 110)],
                           [NSValue valueWithCGPoint:CGPointMake(270, 80)],
                           [NSValue valueWithCGPoint:CGPointMake(180, 80)],
                           [NSValue valueWithCGPoint:CGPointMake(140, 120)]];

    // 创建连接星点的路径
    UIBezierPath *linePath = [UIBezierPath bezierPath];

    for (int i = 0; i < positions.count; i++) {
        CGPoint center = [positions[i] CGPointValue];

        // 创建CAShapeLayer表示一个点
        CAShapeLayer *dotLayer = [CAShapeLayer layer];
        dotLayer.fillColor = [UIColor whiteColor].CGColor;

        // 创建一个小圆点路径
        UIBezierPath *dotPath = [UIBezierPath bezierPathWithArcCenter:center
                                                               radius:2.0
                                                           startAngle:0
                                                             endAngle:M_PI * 2
                                                            clockwise:YES];
        dotLayer.path = dotPath.CGPath;

        // 将点添加到黑色视图的图层中
        [blackView.layer addSublayer:dotLayer];

        // 在路径中添加点以绘制线
        if (i == 0) {
            [linePath moveToPoint:center];
        } else {
            [linePath addLineToPoint:center];
        }
    }

    // 创建CAShapeLayer用于绘制线条
    CAShapeLayer *lineLayer = [CAShapeLayer layer];
    lineLayer.strokeColor = [UIColor whiteColor].CGColor;
    lineLayer.lineWidth = 1.0;
    lineLayer.path = linePath.CGPath;

    // 将线条添加到黑色视图的图层中
    [blackView.layer addSublayer:lineLayer];
}


@end
